package com.example.chatroom.api;


import com.example.chatroom.mapper.MessageMapper;
import com.example.chatroom.model.Message;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController
public class MessageAPI {
    @Resource
    private MessageMapper messageMapper;

    @GetMapping("/message")
    public Object getMessage(int sessionId) {
        List<Message> messages =  messageMapper.getMessagesBySessionId(sessionId);
        // 针对查询结果进行逆序
        Collections.reverse(messages);
        System.out.println("[getMessage] 历史消息返回成功!");
        return messages;
    }
}
